<?php

namespace App\Containers\AppSection\Pledge\UI\API\Transformers;

use App\Containers\AppSection\File\UI\API\Transformers\FileTransformer;
use App\Containers\AppSection\Pledge\Models\DDU;
use App\Ship\Parents\Transformers\Transformer;
use League\Fractal\Resource\Collection;

class DDUTransformer extends Transformer
{
    protected array $defaultIncludes = [
        'plans', 'documents'
    ];

    /**
     * @param DDU $t
     * @return array
     */
    public function transform(DDU $t): array
    {
        return [
            'object' => $t->getResourceKey(),
            'include' => $this->getAvailableIncludes(),
            'id' => $t->getHashedKey(),
            'number' => $t->number,
            'date' => $t->date,
            'developer' => $t->developer,
            'ogrn_developer' => $t->ogrn_developer,
            'registration_region' => $t->registration_region,
            'registration_number' => $t->registration_number,
            'sum' => $t->sum,
            'address' => $t->address,
            'total_area' => $t->total_area,
            'floor' => $t->floor,
            'floors_number' => $t->floors_number,
            'conditional_number' => $t->conditional_number,
            'transfer_date' => $this->dateFormatter($t->transfer_date),
            'other_information' => $t->other_information,
        ];
    }

    public function includeDocuments(DDU $t): Collection
    {
        return $this->collection($t->documents()->get(), new FileTransformer);
    }

    public function includePlans(DDU $t): Collection
    {
        return $this->collection($t->plans()->get(), new FileTransformer);
    }
}
